package 二叉树相关问题.中度题;

import java.util.HashMap;
import java.util.Map;

//在受污染的二叉树中寻找元素
public class FindElements {
    Map<Integer, Integer> map = new HashMap<>();
    public FindElements(TreeNode root) {
        traverse(root,0);
    }

    private void traverse(TreeNode root, int v) {
        if (root==null)
            return;
        root.val=0;
        map.put(v,1);
        traverse(root.left,2*v+1);
        traverse(root.right,2*v+2);
    }

    public boolean find(int target) {
         return map.containsKey(target);
    }
}
